Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following C declarationstruct { ... Start Learning for Free
Consider the following C declaration
struct { 
    short s[5];
    union { 
         float y; 
         long z; 
    }u; 
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is 
  • a)
    22 bytes
  • b)
    14 bytes
  • c)
    18 bytes
  • d)
    10 bytes
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
Consider the following C declarationstruct { short s[5]; union { ...
The given C declaration defines a structure named "t" with two members: an array of 5 shorts named "s" and a union named "u" which has two possible members, a float named "y" and a long named "z".

Memory Requirement Calculation:
To calculate the memory requirement for variable t, we need to consider the size of each member and any padding that may be added for alignment considerations.

1. Size of the short array "s":
Since each short occupies 2 bytes, the total size of the short array is 5 * 2 = 10 bytes.

2. Size of the union "u":
The size of a union is determined by the size of its largest member. In this case, the float "y" occupies 4 bytes and the long "z" occupies 8 bytes. Thus, the size of the union is 8 bytes.

3. Size of the structure "t":
The size of a structure is determined by the sum of the sizes of its members. In this case, the size of the structure is the sum of the size of the short array and the size of the union, which is 10 bytes + 8 bytes = 18 bytes.

Therefore, the memory requirement for variable t, ignoring alignment considerations, is 18 bytes.

Note: The given answer option 'C' is correct.
Free Test
Community Answer
Consider the following C declarationstruct { short s[5]; union { ...
Short array s[5] will take 10 bytes as size of short is 2 bytes.
When we declare a union, memory allocated for the union is equal to memory needed for the largest member of it, and all members share this same memory space. Since u is a union, memory allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 + 8).
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer?
Question Description
Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer?.
Solutions for Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following C declarationstruct { short s[5]; union { float y; long z; }u;} t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa)22 bytesb)14 bytesc)18 bytesd)10 bytesCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev